/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */
package seedpod.model;

import seedpod.kb2db.SlotMap;

@Deprecated
public class AVPairFactory {

	/** 
	 * Must make sure that the int index given to a binder corresponds
	 * to the position in the BINDER_COLLECTION array
	 */
	public static final int DEFAULT_BINDER = 0;
	public static final String[] BINDER_COLLECTION = { "DEFAULT" };

	private static AVPairFactory _instance;
	
	private AVPairFactory() {}

	public static AVPairFactory getInstance() {
		if ( _instance == null )
			_instance = new AVPairFactory();
		return _instance;
	}

	protected AVPair getDefault( SeedpodDO object, SlotMap att ) {
		return new AVPair( object, att );
	}

	public String getDefaultBinderName() {
		return BINDER_COLLECTION[DEFAULT_BINDER];
	}
	
	private int getType( String typeName ) {
		for ( int i = 0; i < BINDER_COLLECTION.length; i++ ) {
			if ( typeName.equalsIgnoreCase( BINDER_COLLECTION[i] ) )
				return i;
		}
		return DEFAULT_BINDER;
	}

	/**
	 * The type of binder returned can be set in the slotmap descriptively (similar to widgets) But here, we are going
	 * to do it programmatically for now.
	 * 
	 * @param object
	 * @param att
	 * @return
	 */
	public AVPair createBinder( SeedpodDO object, SlotMap att, String binderName ) {
		int type = getType( binderName );
		return createBinder( object, att, type );
	}
	
	
	
	/**
	 * Figure out the right default binder based on the slotmap that's given. 
	 * @param object
	 * @param att
	 * @return
	 */
	public AVPair createDefaultBinder( SeedpodDO object, SlotMap att) {
		return createBinder(object, att, DEFAULT_BINDER);
	}
	

	// one can imagine adding other types of binders here
	private AVPair createBinder( SeedpodDO object, SlotMap att, int type ) {
		AVPair binder;

		switch (type) {

		default:
			binder = new AVPair( object, att );
			break;
		}
		return binder;
	}

	/** 
	 * TODO this is supposed to get the name of the binder from the slotmap
	 * And for now they are  DEFAULT  b/c the definition in slotmap isn't implemented yet
	 * @param object
	 * @param att
	 * @return
	 */
	public AVPair getDefaultBinder( SeedpodDO object, SlotMap att ) {
		return createBinder(object, att, DEFAULT_BINDER);
	}

}
